const sm4= require('sm-crypto').sm4
 
function strToHex(str) {
    var hexCharCode = [];
    
    for (var i = 0; i < str.length; i++) {
      hexCharCode.push(str.charCodeAt(i).toString(16));
    }
    // 记住这里的join一定是空，不要误打了空格
    return hexCharCode.join('');
  }

let data = 'hello,world';
let key = '0123456789abcdef';
let hexKey = strToHex(key) //"71d475aebcb76cbd00aa5892a4d5dd75"
console.log(hexKey)

hexKey = "243bf1cc9028c2f240ef82d871d1398f"

let cipherText = sm4.encrypt(data,hexKey)
let decrypted = sm4.decrypt(cipherText,hexKey)
console.log('加密后的密文:',cipherText)
console.log('解密后的密文:',decrypted)
